function loadRoomType(){
	$.ajax({
		url:"../../roomtype/all",
		type:"get",
		dataType:"json",
		success:function(data){
			var content = "";
			for (var i = 0; i < data.length; i++) {
				roomtype=data[i];
				content +='<tr>'
						+'<td>'+roomtype.type+'</td>'
						+'<td>'+roomtype.contain+'</td>'
						+'<td>'+roomtype.price+'</td>'
						+'<td>'+roomtype.deposit+'</td>'
						+'<td>'
						+'<a class="layui-btn layui-btn-sm" onclick="deleteRoomType('+roomtype.roomtype_id+')"><i class="layui-icon"></i>删除</a>'
						+'<a class="layui-btn layui-btn-sm" onclick="updateRoomType('+roomtype.roomtype_id+')"><i class="layui-icon"></i>修改</a>'
						+'</td>'
						+'</tr>';
				
				
				
			}
			
			$("#roomtype").html(content);
			
			
		}

		
		
		
	});
	
	
	
}
loadRoomType();

//添加房间
function addRoomType() {
	layui.use('layer', function() {
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "添加房间",
			type: 2,
			area: ['45%', '50%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'addRoomType.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child()
			}
		});
	});
}

//修改房间类型
function updateRoomType(roomtype_id) {
	layui.use('layer', function() {
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "修改房间类型信息",
			type: 2,
			area: ['40%', '50%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'updateRoomType.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child(roomtype_id)
			}
		});
	});
}






//删除房间类型
function deleteRoomType(roomtype_id){
	$.ajax({
		url:"../../roomtype/delete",
		type:"post",
		dataType:"json",
		
		data:{
			"roomtype_id":roomtype_id
			
		},
		success:function(data){
			if(data==0){
				alert("删除失败，该类型尚有房间");
				loadRoomType();
			}else{
				
				loadRoomType();
			}
			
			
			
		}
	});
}

